package com.wlsk.license.common.result;

import com.wlsk.license.common.enums.PlateRetEnum;
import lombok.Data;

import java.io.Serializable;

@Data
public class PlateResult<T> implements Serializable {

    private static final long serialVersionUID = -3647103278357796191L;
    private Integer code; //状态码
    private String desc;  //返回信息
    private T data;  //返回数据

    private PlateResult() {
    }

    public static <T> PlateResult<T> success() {
        PlateResult<T> result = new PlateResult<T>();
        result.code = PlateRetEnum.SUCCESS.getCode();
        result.desc = PlateRetEnum.SUCCESS.getMsg();
        return result;
    }

    public static <T> PlateResult<T> success(String msg) {
        PlateResult<T> result = new PlateResult<T>();
        result.code = PlateRetEnum.SUCCESS.getCode();
        result.desc = msg;
        return result;
    }

    public static <T> PlateResult<T> success(T data) {
        PlateResult<T> result = new PlateResult<T>();
        result.code = PlateRetEnum.SUCCESS.getCode();
        result.desc = PlateRetEnum.SUCCESS.getMsg();
        result.data = data;
        return result;
    }

    public static <T> PlateResult<T> success(T data, Long total) {
        PlateResult<T> result = new PlateResult<T>();
        result.code = PlateRetEnum.SUCCESS.getCode();
        result.desc = PlateRetEnum.SUCCESS.getMsg();
        result.data = data;
        return result;
    }

    public static <T> PlateResult<T> success(int code, T data) {
        PlateResult<T> result = new PlateResult<T>();
        result.code = code;
        result.desc = PlateRetEnum.SUCCESS.getMsg();
        result.data = data;
        return result;
    }

    public static <T> PlateResult<T> success(String msg, T data) {
        PlateResult<T> result = success(msg);
        result.data = data;
        return result;
    }


    public static <T> PlateResult<T> failed() {
        PlateResult<T> result = new PlateResult<T>();
        result.code = PlateRetEnum.FAILED.getCode();
        result.desc = PlateRetEnum.FAILED.getMsg();
        return result;
    }

    public static <T> PlateResult<T> failed(String msg) {
        PlateResult<T> result = new PlateResult<T>();
        result.code = PlateRetEnum.FAILED.getCode();
        result.desc = msg;
        return result;
    }

    public static <T> PlateResult<T> failed(Integer code, String msg) {
        PlateResult<T> result = new PlateResult<>();
        result.code = code;
        result.desc = msg;
        return result;
    }

    public static <T> PlateResult<T> failed(PlateRetEnum retEnum) {
        PlateResult<T> result = new PlateResult<>();
        result.code = retEnum.getCode();
        result.desc = retEnum.getMsg();
        return result;
    }

    public static <T> PlateResult<T> failed(T obj) {
        PlateResult<T> result = failed();
        result.data = obj;
        return result;
    }

    public static <T> PlateResult<T> failed(Integer code, String msg, T obj) {
        PlateResult<T> result = new PlateResult<>();
        result.code = code;
        result.desc = msg;
        result.data = obj;
        return result;
    }

    public Boolean isSuccess() {
        return PlateRetEnum.SUCCESS.getCode().equals(this.code);
    }
}
